package longcaisuyun.longcai.com.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.zcx.helper.http.AsyCallBack;

import longcaisuyun.longcai.com.net.PostShop;
import longcaisuyun.longcai.com.yiliubabalongcaisuyun.MyApplication;
import longcaisuyun.longcai.com.yiliubabalongcaisuyun.R;
import longcaisuyun.longcai.com.yiliubabalongcaisuyun.ShopAdapter;


/**
 * Created by Administrator on 2016/2/18.
 */
public class frag_main_shop extends Fragment {
    private  boolean shuaXin=false;
    ListView listView7;
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = View.inflate(getActivity(), R.layout.frag_main_shop, null);
        MyApplication.ScaleScreenHelper.loadView((ViewGroup) v);
        listView7 = (ListView) v.findViewById(R.id.listView7);
        HttpPost();
        return v;
    }

    public void HttpPost() {
        MyApplication.myviewutil.startProgressDialog(getActivity());
        new PostShop("", new AsyCallBack<PostShop.Info>() {
            @Override
            public void onSuccess(String toast, int type, PostShop.Info info) throws Exception {
                super.onSuccess(toast, type, info);
                if (info.message.equals("1")) {
                    listView7.setAdapter(new ShopAdapter(getActivity(), info.list));

                } else {
                    Toast.makeText(getActivity(), "获取数据失败", Toast.LENGTH_SHORT).show();
                }
                MyApplication.myviewutil.stopProgressDialog();
                shuaXin=false;
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                shuaXin=true;
                MyApplication.myviewutil.stopProgressDialog();
                Toast.makeText(getActivity(), "获取数据失败", Toast.LENGTH_SHORT).show();
            }
        }).execute(getActivity());
    }
    public  void change(){
        if (shuaXin){
            HttpPost();
        }
    }
}
